home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / Sessions / Completions / Demo Application / main.cp < prev    next >
Encoding:
Text File  |  1998-06-19  |  1.9 KB  |  96 lines  |  [TEXT/CWIE]

  1. // main.cp
  2.  
  3. #ifndef FileCopier_h
  4. #include "FileCopier.h"
  5. #endif
  6. #ifndef __ERRORS__
  7. #include <Errors.h>
  8. #endif
  9. #ifndef __WINDOWS__
  10. #include <Windows.h>
  11. #endif
  12. #ifndef __FONTS__
  13. #include <Fonts.h>
  14. #endif
  15. #ifndef __DIALOGS__
  16. #include <Dialogs.h>
  17. #endif
  18. #ifndef Appearance_h
  19. #include "Appearance.h"
  20. #endif
  21. #ifndef Controls_h
  22. #include "Controls.h"
  23. #endif
  24.  
  25. void main()
  26.   {
  27.     FSSpec spec;
  28.     OSErr error = FSMakeFSSpec( -1, 2, "\pTroops", &spec );
  29.     Assert( error == noErr );
  30.  
  31.     FSSpec spec2;
  32.     error = FSMakeFSSpec( -1, 2, "\pTroops copy", &spec2 );
  33.     if ( error != fnfErr )
  34.         FSpDelete( &spec2 );
  35.     
  36.     static FileCopier copier;
  37.     TaskLife life;
  38.     
  39.     life.Launch( copier( spec, spec2 ) );
  40.     
  41.     InitGraf( &qd.thePort );
  42.     InitFonts();
  43.     InitWindows();
  44.     InitMenus();
  45.     InitDialogs( 0 );
  46.     FlushEvents( everyEvent, 0 );
  47.     RegisterAppearanceClient();
  48.     
  49.     MenuHandle apple = GetMenu( 128 );
  50.     AppendResMenu( apple, 'DRVR' );
  51.     InsertMenu( apple, 0 );
  52.     InsertMenu( GetMenu( 129 ), 0 );
  53.     DialogPtr progress = GetNewDialog( 128, 0, WindowPtr(-1) );
  54.     
  55.     ControlHandle progressBar;
  56.     int16 itemType;
  57.     Rect itemBox;
  58.     GetDialogItem( progress, 2, &itemType, reinterpret_cast<Handle*>(&progressBar), &itemBox );
  59.     DrawMenuBar();
  60.     
  61.     while ( 1 )
  62.       {
  63.         EventRecord event;
  64.         uint32 sleepTime = ApplicationTaskQueue::The().IsEmpty() ? 6 : 0;
  65.         WaitNextEvent( everyEvent, &event, sleepTime, 0 );
  66.         
  67.         if ( IsDialogEvent( &event ) )
  68.           {
  69.             DialogPtr dialog;
  70.             int16 item;
  71.             DialogSelect( &event, &dialog, &item );
  72.           }
  73.         
  74.         switch ( event.what )
  75.           {
  76.             case mouseDown:
  77.               {
  78.                 WindowPtr window;
  79.                 int16 part = FindWindow( event.where, &window );
  80.                 if ( part == inMenuBar )
  81.                     if ( MenuSelect( event.where ) != 0 )
  82.                         return;
  83.                 break;
  84.               }
  85.             
  86.             case nullEvent:
  87.                 ApplicationTaskQueue::The().ExecuteOne();
  88.                 int32 total = copier.MaxPosition() / 100000;
  89.                 int32 position = copier.Position() / 100000;
  90.                 if ( total != 0 )
  91.                     SetControlValue( progressBar, position*100 / total );
  92.                 break;
  93.           }
  94.       }
  95.   }
  96.